const util = require('../../../utils/util.js');
const api = require('../../../config/api.js');
var app = getApp();
Page({
  data: {
    coachs: [],
    navbar_bgcolor: wx.getStorageSync('navbar_bgcolor'),
    coachName1:'',
    coachName2:'',
    coachName3:'',
    coachName4:'',
    phone1:'',
    phone2:'',
    phone3:'',
    phone4:''
  },
  onLoad: function () {
    var that = this;
    that.getCoachs();
  },
  getCoachs: function () {
    var hasLogin = wx.getStorageSync("app.globalData.hasLogin");
    if (!hasLogin) {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    }

    wx.showLoading({
      title: '加载中...',
    })
    var that = this;
    var userid = wx.getStorageSync("userid");
    if(userid == ''){
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
      return;
    }
    util.request(api.MyCoachInfo, {uid:userid,key:api.key}).then(function (res) {
      //console.log('vvvvvvvv'+JSON.stringify(res));
      console.log(res)
      if (res.errno === 0) {
        var list = res.data.list;
        //console.log('vvvvvvvv'+JSON.stringify(list));
        list.forEach(function(item, index){
          //console.log(item.subject);
          //console.log(index);
          if(item.subject == '1'){
            that.setData({coachName1:item.coachName})
            that.setData({phone1:item.phone})
          }
          if(item.subject == '2'){
            that.setData({coachName2:item.coachName})
            that.setData({phone2:item.phone})
          }
          if(item.subject == '3'){
            that.setData({coachName3:item.coachName})
            that.setData({phone3:item.phone})
          }
          if(item.subject == '4'){
            that.setData({coachName4:item.coachName})
            that.setData({phone4:item.phone})
          }
        })
      }else if(res.errno === 402){
        wx.showModal({
          title: '错误',
          content:'不被允许的请求',
          showCancel: false
        })
    }else{
        wx.showToast({
          title: res.errmsg,
          icon: 'none',
          duration: 2500
      })
      }
    });
    wx.hideLoading();
  }

})